package com.itheima.controller;

import com.itheima.R;
import com.itheima.dto.GetOrderDto;
import com.itheima.dto.OmsOrderDto;
import com.itheima.dto.deliveryDto;
import com.itheima.dto.MoneyInfoParam;
import com.itheima.dto.receiverInfoParam;
import com.itheima.service.OmsOrderService;
import com.itheima.vo.MinioVo;
import com.itheima.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 芝士雪豹
 * @create 2022/10/13/20:26
 */
@RestController
@RequestMapping("/order")
public class OmsOrderController {
    @Autowired
    private OmsOrderService omsOrderService;

    //批量删除订单
    @PostMapping("delete")
    public MinioVo delete(@PathVariable Integer[] ids) {
        MinioVo vo = omsOrderService.delete(ids);
        return vo;
    }

    //查询订单
    @GetMapping("list")
    public R findOrder(@RequestBody OmsOrderDto dto) {
        PageResult pageResult = omsOrderService.findOrder(dto);
        return R.success(pageResult);
    }

    //批量关闭订单
    @PostMapping("/update/close")
    public MinioVo close(@RequestBody Integer[] ids, String note) {
        MinioVo vo = omsOrderService.close(ids, note);
        return vo;
    }

    //批量发货
    @PostMapping("/update/delivery")
    public MinioVo delivery(@RequestBody deliveryDto dto) {
        MinioVo vo = omsOrderService.delivery(dto);
        return vo;
    }

    //修改订单费用信息
    @PostMapping("/update/moneyInfo")
    public MinioVo moneyInfo(@RequestBody MoneyInfoParam moneyInfoParam) {
        MinioVo vo = omsOrderService.moneyInfo(moneyInfoParam);
        return vo;
    }

    //备注订单
    @PostMapping("/update/note")
    public MinioVo note(@RequestBody Integer id, String note, Integer status) {
        MinioVo vo = omsOrderService.note(id, note, status);
        return vo;
    }

    //修改收货人信息
    @PostMapping("/update/receiverInfo")
    public MinioVo receiverInfo(@RequestBody receiverInfoParam param) {
        MinioVo vo = omsOrderService.receiverInfo(param);
        return vo;
    }

    //获取订单详情：订单信息、商品信息、操作记录
    @GetMapping("/{id}")
    public R findAll(@PathVariable Integer id) {
        GetOrderDto pageResult = omsOrderService.getOrder(id);
        return R.success(pageResult);
    }


}
